package logic

import (
	"commodity/commodityrpc/commodityrpc"
	"commodity/commodityrpc/internal/svc"
	"commodity/model/mysql"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsAddLogic {
	return &GoodsAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsAddLogic) GoodsAdd(in *commodityrpc.GoodsAddRequest) (*commodityrpc.GoodsAddResponse, error) {
	// todo: add your logic here and delete this line
	goods := mysql.Goods{
		Name:      in.Name,
		Price:     float64(in.Price),
		Image:     in.Image,
		Inventory: int(in.Inventory),
		Status:    int(in.Status),
		Method:    int(in.Method),
	}
	mysql.DB.Create(&goods)
	return &commodityrpc.GoodsAddResponse{
		GoodsId: int64(goods.ID),
	}, nil
}
